package cn.hnbjx.prepaid.service;

import cn.hnbjx.prepaid.common.BusinessException;
import cn.hnbjx.prepaid.common.BusinessStatus;
import cn.hnbjx.prepaid.dao.FileDao;
import cn.hnbjx.prepaid.pojo.File;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileService {
    @Autowired
    private FileDao fileDao;

    //分页查询全部文件
    public PageInfo<File> findByFileAll(Integer page, Integer pageSize){
        PageHelper.startPage(page, pageSize);
        List<File> byFileAll = fileDao.findByFileAll();
        PageInfo<File> filePageInfo = new PageInfo<>(byFileAll);
        return filePageInfo;
    }

    //删除文件
    public void DeleteFile(Integer fileId){
        int i = fileDao.DeleteFile(fileId);
        if (0 == i) throw new BusinessException(BusinessStatus.FAIL);
    }


}